﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TransportHierarchyWithForms
{

    public enum LoggerType
    {
        CONSOLE = 1, FILE = 2
    }

    public interface ILogger
    {
        string Log(string message);
    }

    public class ConsoleLogger : ILogger
    {
        public string Log (string message)
        {
		    //реализация
            string Sum = "";
            Sum+="/////////////////////////////////////////////////////////////////////"+'\n'
            +"Сейчас происходит: "+'\n'
            +message+'\n'+
            "/////////////////////////////////////////////////////////////////////"+'\n';
            return Sum;
        }
    }

    public class FileLogger : ILogger
    {
        public string Log (string message)
        {
            //реализация
            using (System.IO.StreamWriter file = new System.IO.StreamWriter("log.txt", true))
            {
     
                file.WriteLine("/////////////////////////////////////////////////////////////////////");
                file.WriteLine("Сейчас происходит: ");
                file.WriteLine(message);
                file.WriteLine("/////////////////////////////////////////////////////////////////////");
                file.Close();
                return "";
            }
        }
    }

    public class LoggerFactory
    {
        public LoggerFactory(){ }

	    public ILogger CreateLogger(uint type)
        {
            ILogger newLogger = null;
            switch (type)
            {
                case (uint)LoggerType.CONSOLE: newLogger=new ConsoleLogger();
                    break;
                case (uint)LoggerType.FILE: newLogger=new FileLogger();
                    break;
                default: throw new ArgumentException("Invalid type.", "type");
            }
            return newLogger;
        }
    }

}
